﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Conventions;

namespace Landscape.ConsoleTest
{
    public class TableNameConvention : IClassConvention
    {        
        public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance)
        {
            string tname = string.Empty;
            int idx = 0;
            foreach (char ltr in instance.EntityType.Name)
            {
                if (ltr.Equals(ltr.ToString().ToUpper().ToCharArray()[0]))
                {
                    if (idx != 0)
                    {
                        tname += "_";
                    }
                    tname += ltr.ToString();
                }
                else
                {
                    tname += ltr.ToString().ToUpper();
                }
                idx++;
            }
            instance.Table(tname);
        }       

    }
}
